//弹窗高度
function changePopupHeigth(obj,heightReduce) {
    var popupHeight = 0;
    if (window.innerHeight) {
        popupHeight = window.innerHeight;
    } else if ((document.body) && (document.documentElement.clientHeight)) {
        popupHeight = document.documentElement.clientHeight;
    }
    var topheight = popupHeight*heightReduce;
    obj.css("max-height",topheight);
}
//改变窗体大小以及设置Map和Pie高度
function changeHeitht(obj,heightReduce) {
    var winHeight = 0;
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    } else if ((document.body) && (document.documentElement.clientHeight)) {
        winHeight = document.documentElement.clientHeight;
    }
    var topheight = winHeight - heightReduce;
    obj.height(topheight);
}

//时间转换
function formatDate(now) {
    var year=now.getFullYear();
    var month=checkTime(now.getMonth()+1);
    var date=checkTime(now.getDate());
    var hour=checkTime(now.getHours());
    var minute=checkTime(now.getMinutes());
    var second=checkTime(now.getSeconds());
    return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}
function checkTime(i) {
    if (i<10) {i="0" + i}
    return i;
}
//报警数目

function alarmInfo() {
    BJUI.dialog({
        id:'alarmInfo',
        width: 600,
        height: 500,
        refresh:true,
        url:'/sysmanage/devicealarm/alarmInfo.do',
        title:'告警信息'
    })
}
function alarmNum() {
    $.ajax({
        url: "/sysmanage/devicealarm/getAlarmNum.do",
        data: "",
        type: "post",
        dataType: "json",
        success: function (data) {

            if(lastAlarmId!=data.lastAlarmID && data.lastAlarmID!=0) {
                lastAlarmId = data.lastAlarmID;
                if($("[title='实时监控<span></span>']").length>0){
                    BJUI.navtab('refresh', 'time');
                    alarmInfo();
                }else{
                    BJUI.navtab({
                        id:'time',
                        refresh:true,
                        url:'/sysmanage/devicemonitor/location.do',
                        title:'实时监控<span></span>'
                    })
                    alarmInfo();
                }
            }


            if(data.deviceAlarmNum==0){
                $(".devicealarm-class").html("");
                $("#bjui-sidenav-box").find("span").removeClass("devicealarm-class");
            }else{

                if (window.ActiveXObject || "ActiveXObject" in window){
                    $('#newMessageDIV').html('<embed src="/assets/images/alarm.wav"/>');
                }else{
                    $('#newMessageDIV').html('<audio autoplay="autoplay"><source src="/assets/images/alarm.wav"'
                        + 'type="audio/wav"></audio>');
                }
                $("#bjui-sidenav-box").find("span").addClass("devicealarm-class");
                $(".devicealarm-class").html(data.deviceAlarmNum);
            }
            if(data.allAlarmNum==0){
                $(".allAlarm-class").html("");
                $("#bjui-sidenav-box").find("p").removeClass("allAlarm-class");
            }else{

                $("#bjui-sidenav-box").find("p").addClass("allAlarm-class");
                $(".allAlarm-class").html(data.allAlarmNum);
            }
        },
        complete:function () {
            timer=setTimeout("alarmNum()",60000);
        }

    });
}
// datepicker基本设置
function datepickerBasicConfiguration(start,end) {
    $.datepicker.parseDate("yy/mm/dd", "2007/01/26");
    start.datetimepicker({
        defaultDate: start.val(),
        timeFormat: "HH:mm:ss",
        dateFormat: "yy-mm-dd",
        changeMonth: true,
        onClose: function (selectedDate) {
            end.datepicker("option", "minDate", selectedDate);
        }
    });
    end.datetimepicker({
        defaultDate: end.val(),
        timeFormat: "HH:mm:ss",
        dateFormat: "yy-mm-dd",
        changeMonth: true,
        onClose: function (selectedDate) {
            start.datepicker("option", "maxDate", selectedDate);
        }
    });
}

function G(id) {
    return document.getElementById(id);
}
function pullDownEvents(ac,obj) {
    ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
        var str = "";
        var _value = e.fromitem.value;
        var value = "";
        if (e.fromitem.index > -1) {
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

        value = "";
        if (e.toitem.index > -1) {
            _value = e.toitem.value;
            value = _value.province + _value.city + _value.district + _value.street + _value.business;
        }
        str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
        G(obj).innerHTML = str;
    });
}



